intersect.js ➔ intersect   A
last analyzed

Complexity

Conditions 5

Size

Total Lines 21
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 5

Importance

Changes 0
Metric Value
eloc 13
dl 0
loc 21
ccs 11
cts 11
cp 1
rs 9.2833
c 0
b 0
f 0
cc 5
crap 5
1
import toJson from './toJson.js';
2
3
export default function intersect(original, array, multi) {
4 4
    const jsonValue = toJson(array);
5 4
    const arrayLength = array.length;
6
7 4
    return original.filter((value) => {
8 12
        const valueToJson = JSON.stringify(value);
9 12
        if (multi) {
10 6
            const found = jsonValue.reduce((accumulator, currentValue) => {
11 12
                if (currentValue.includes(valueToJson)) {
12 8
                    return accumulator + 1;
13
                }
14
15 4
                return accumulator;
16
            }, 0);
17
18 6
            return found === arrayLength;
19
        }
20
21 6
        return jsonValue.includes(valueToJson);
22
    });
23
}
24